
package xbean.__;

import java.io.StringReader;
import java.io.StringWriter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.goldhuman.Common.Marshal.OctetsStream;
import com.goldhuman.Common.Marshal.MarshalException;

public final class Role extends xdb.XBean implements xbean.Role {
	private String rolename; // null
	private long userid; // null
	private long lastlogintime; // null

	@Override
	public void _reset_unsafe_() {
		rolename = "";
		userid = 0L;
		lastlogintime = 0L;
	}

	Role(int __, xdb.XBean _xp_, String _vn_) {
		super(_xp_, _vn_);
		rolename = "";
	}

	public Role() {
		this(0, null, null);
	}

	public Role(Role _o_) {
		this(_o_, null, null);
	}

	Role(xbean.Role _o1_, xdb.XBean _xp_, String _vn_) {
		super(_xp_, _vn_);
		if (_o1_ instanceof Role) {
			assign((Role)_o1_);
		} else if (_o1_ instanceof Role.Data) {
			assign((Role.Data)_o1_);
		} else if (_o1_ instanceof Role.Const) {
			assign(((Role.Const)_o1_).nThis());
		} else {
			throw new UnsupportedOperationException();
		}
	}

	private void assign(Role _o_) {
		_o_._xdb_verify_unsafe_();
		rolename = _o_.rolename;
		userid = _o_.userid;
		lastlogintime = _o_.lastlogintime;
	}

	private void assign(Role.Data _o_) {
		rolename = _o_.rolename;
		userid = _o_.userid;
		lastlogintime = _o_.lastlogintime;
	}

	@Override
	public final OctetsStream marshal(OctetsStream _os_) {
		_xdb_verify_unsafe_();
		try {
			StringWriter sw = new StringWriter();
			JsonWriter _out_ = new JsonWriter(sw);
			marshal(_out_);
			_os_.marshalJson(sw.getBuffer().toString());
			_out_.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void marshal(JsonWriter _out_) throws Exception {
		_out_.beginObject();
		if (rolename.isEmpty() == false) {
			_out_.name("1");
			_out_.value(this.rolename);
		}
		if (userid != 0L) {
			_out_.name("2");
			_out_.value(this.userid);
		}
		if (lastlogintime != 0L) {
			_out_.name("3");
			_out_.value(this.lastlogintime);
		}
		_out_.endObject();
	}

	@Override
	public final OctetsStream unmarshal(OctetsStream _os_) {
		_xdb_verify_unsafe_();
		try {
			JsonReader jr = new JsonReader(new StringReader(_os_.unmarshalJson()));
			unmarshal(jr);
			jr.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void unmarshal(JsonReader _in_) throws Exception {
		_in_.beginObject();
		while (_in_.hasNext()) {
			switch (_in_.nextName()) {
				case "1":
					this.rolename = _in_.nextString();
					break;
				case "2":
					this.userid = _in_.nextLong();
					break;
				case "3":
					this.lastlogintime = _in_.nextLong();
					break;
				default:
					_in_.skipValue();
					break;
			}
		}
		_in_.endObject();
	}

	@Override
	public xbean.Role copy() {
		_xdb_verify_unsafe_();
		return new Role(this);
	}

	@Override
	public xbean.Role toData() {
		_xdb_verify_unsafe_();
		xbean.__.Role.Data tmp = (Data) xbean.Pod.newRoleData();
		tmp.assign(this);
		return tmp;
	}

	public xbean.Role toBean() {
		_xdb_verify_unsafe_();
		return new Role(this); // same as copy()
	}

	@Override
	public xbean.Role toDataIf() {
		_xdb_verify_unsafe_();
		return new Data(this);
	}

	public xbean.Role toBeanIf() {
		_xdb_verify_unsafe_();
		return this;
	}

	@Override
	public xdb.Bean toConst() {
		_xdb_verify_unsafe_();
		return new Const();
	}

	@Override
	public String getRolename() { // null
		_xdb_verify_unsafe_();
		return rolename;
	}

	@Override
	public com.goldhuman.Common.Octets getRolenameOctets() { // null
		_xdb_verify_unsafe_();
		return com.goldhuman.Common.Octets.wrap(getRolename(), xdb.Const.IO_CHARSET);
	}

	@Override
	public long getUserid() { // null
		_xdb_verify_unsafe_();
		return userid;
	}

	@Override
	public long getLastlogintime() { // null
		_xdb_verify_unsafe_();
		return lastlogintime;
	}

	@Override
	public void setRolename(String _v_) { // null
		_xdb_verify_unsafe_();
		if (null == _v_) {
			throw new NullPointerException();
		}
		if(_v_.equals(rolename)) {
		    return;
		}
		xdb.Logs.logIf(new xdb.LogKey(this, "rolename") {
			protected xdb.Log create() {
				return new xdb.logs.LogString(this, rolename) {
					public void rollback() {
						rolename = _xdb_saved;
					}
					public boolean checkNoChange(Object v) {
						return v.equals(_xdb_saved);
					}
				};
			}
		}, _v_);
		rolename = _v_;
	}

	@Override
	public void setRolenameOctets(com.goldhuman.Common.Octets _v_) { // null
		_xdb_verify_unsafe_();
		this.setRolename(_v_.getString(xdb.Const.IO_CHARSET));
	}

	@Override
	public void setUserid(long _v_) { // null
		_xdb_verify_unsafe_();
		if(userid == _v_) {
		    return;
		}
		xdb.Logs.logIf(new xdb.LogKey(this, "userid") {
			protected xdb.Log create() {
				return new xdb.logs.LogLong(this, userid) {
					public void rollback() {
						userid = _xdb_saved;
					}
					public boolean checkNoChange(Object v) {
						return (Long)v == _xdb_saved;
					}
				};
			}
		}, _v_);
		userid = _v_;
	}

	@Override
	public void setLastlogintime(long _v_) { // null
		_xdb_verify_unsafe_();
		if(lastlogintime == _v_) {
		    return;
		}
		xdb.Logs.logIf(new xdb.LogKey(this, "lastlogintime") {
			protected xdb.Log create() {
				return new xdb.logs.LogLong(this, lastlogintime) {
					public void rollback() {
						lastlogintime = _xdb_saved;
					}
					public boolean checkNoChange(Object v) {
						return (Long)v == _xdb_saved;
					}
				};
			}
		}, _v_);
		lastlogintime = _v_;
	}

	@Override
	public final boolean equals(Object _o1_) {
		_xdb_verify_unsafe_();
		Role _o_ = null;
		if ( _o1_ instanceof Role ) {
			_o_ = (Role)_o1_;
		} else if ( _o1_ instanceof Role.Const ) {
			_o_ = ((Role.Const)_o1_).nThis();
		} else {
			return false;
		}
		if (!rolename.equals(_o_.rolename)) {
			return false;
		}
		if (userid != _o_.userid) {
			return false;
		}
		if (lastlogintime != _o_.lastlogintime) {
			return false;
		}
		return true;
	}

	@Override
	public final int hashCode() {
		_xdb_verify_unsafe_();
		int _h_ = 0;
		_h_ += rolename.hashCode();
		_h_ += userid;
		_h_ += lastlogintime;
		return _h_;
	}

	@Override
	public String toString() {
		_xdb_verify_unsafe_();
		StringBuilder _sb_ = new StringBuilder();
		_sb_.append("(");
		_sb_.append("'").append(rolename).append("'");
		_sb_.append(",");
		_sb_.append(userid);
		_sb_.append(",");
		_sb_.append(lastlogintime);
		_sb_.append(")");
		return _sb_.toString();
	}

	@Override
	public xdb.logs.Listenable newListenable() {
		xdb.logs.ListenableBean lb = new xdb.logs.ListenableBean();
		lb.add(new xdb.logs.ListenableChanged().setVarName("rolename"));
		lb.add(new xdb.logs.ListenableChanged().setVarName("userid"));
		lb.add(new xdb.logs.ListenableChanged().setVarName("lastlogintime"));
		return lb;
	}

	private class Const implements xbean.Role {
		Role nThis() {
			return Role.this;
		}

		@Override
		public void _reset_unsafe_() {
			throw new UnsupportedOperationException();
		}

		@Override
		public xbean.Role copy() {
			return Role.this.copy();
		}

		@Override
		public xbean.Role toData() {
			return Role.this.toData();
		}

		public xbean.Role toBean() {
			return Role.this.toBean();
		}

		@Override
		public xbean.Role toDataIf() {
			return Role.this.toDataIf();
		}

		public xbean.Role toBeanIf() {
			return Role.this.toBeanIf();
		}

		@Override
		public String getRolename() { // null
			_xdb_verify_unsafe_();
			return rolename;
		}

		@Override
		public com.goldhuman.Common.Octets getRolenameOctets() { // null
			_xdb_verify_unsafe_();
			return Role.this.getRolenameOctets();
		}

		@Override
		public long getUserid() { // null
			_xdb_verify_unsafe_();
			return userid;
		}

		@Override
		public long getLastlogintime() { // null
			_xdb_verify_unsafe_();
			return lastlogintime;
		}

		@Override
		public void setRolename(String _v_) { // null
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public void setRolenameOctets(com.goldhuman.Common.Octets _v_) { // null
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public void setUserid(long _v_) { // null
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public void setLastlogintime(long _v_) { // null
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public xdb.Bean toConst() {
			_xdb_verify_unsafe_();
			return this;
		}

		@Override
		public boolean isConst() {
			_xdb_verify_unsafe_();
			return true;
		}

		@Override
		public boolean isData() {
			return Role.this.isData();
		}

		@Override
		public OctetsStream marshal(OctetsStream _os_) {
			return Role.this.marshal(_os_);
		}

		@Override
		public OctetsStream unmarshal(OctetsStream arg0) throws MarshalException {
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public void marshal(JsonWriter _out_) throws Exception {
			Role.this.marshal(_out_);
		}

		@Override
		public void unmarshal(JsonReader _in_) throws Exception {
			_xdb_verify_unsafe_();
			throw new UnsupportedOperationException();
		}

		@Override
		public xdb.Bean xdbParent() {
			return Role.this.xdbParent();
		}

		@Override
		public boolean xdbManaged() {
			return Role.this.xdbManaged();
		}

		@Override
		public String xdbVarname() {
			return Role.this.xdbVarname();
		}

		@Override
		public Long xdbObjId() {
			return Role.this.xdbObjId();
		}

		@Override
		public boolean equals(Object obj) {
			return Role.this.equals(obj);
		}

		@Override
		public int hashCode() {
			return Role.this.hashCode();
		}

		@Override
		public String toString() {
			return Role.this.toString();
		}

	}

	public static final class Data implements xbean.Role {
		private String rolename; // null
		private long userid; // null
		private long lastlogintime; // null

		@Override
		public void _reset_unsafe_() {
			rolename = "";
			userid = 0L;
			lastlogintime = 0L;
		}

		public Data() {
			rolename = "";
		}

		Data(xbean.Role _o1_) {
			if (_o1_ instanceof Role) {
				assign((Role)_o1_);
			} else if (_o1_ instanceof Role.Data) {
				assign((Role.Data)_o1_);
			} else if (_o1_ instanceof Role.Const) {
				assign(((Role.Const)_o1_).nThis());
			} else {
				throw new UnsupportedOperationException();
			}
		}

		private void assign(Role _o_) {
			rolename = _o_.rolename;
			userid = _o_.userid;
			lastlogintime = _o_.lastlogintime;
		}

		private void assign(Role.Data _o_) {
			rolename = _o_.rolename;
			userid = _o_.userid;
			lastlogintime = _o_.lastlogintime;
		}

	@Override
	public final OctetsStream marshal(OctetsStream _os_) {
		try {
			StringWriter sw = new StringWriter();
			JsonWriter _out_ = new JsonWriter(sw);
			marshal(_out_);
			_os_.marshalJson(sw.getBuffer().toString());
			_out_.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void marshal(JsonWriter _out_) throws Exception {
		_out_.beginObject();
		if (rolename.isEmpty() == false) {
			_out_.name("1");
			_out_.value(this.rolename);
		}
		if (userid != 0L) {
			_out_.name("2");
			_out_.value(this.userid);
		}
		if (lastlogintime != 0L) {
			_out_.name("3");
			_out_.value(this.lastlogintime);
		}
		_out_.endObject();
	}

	@Override
	public final OctetsStream unmarshal(OctetsStream _os_) {
		try {
			JsonReader jr = new JsonReader(new StringReader(_os_.unmarshalJson()));
			unmarshal(jr);
			jr.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return _os_;
	}

	@Override
	public final void unmarshal(JsonReader _in_) throws Exception {
		_in_.beginObject();
		while (_in_.hasNext()) {
			switch (_in_.nextName()) {
				case "1":
					this.rolename = _in_.nextString();
					break;
				case "2":
					this.userid = _in_.nextLong();
					break;
				case "3":
					this.lastlogintime = _in_.nextLong();
					break;
				default:
					_in_.skipValue();
					break;
			}
		}
		_in_.endObject();
	}

		@Override
		public xbean.Role copy() {
			return new Data(this);
		}

		@Override
		public xbean.Role toData() {
			xbean.__.Role.Data tmp = (Data) xbean.Pod.newRoleData();
			tmp.assign(this);
			return tmp;
		}

		public xbean.Role toBean() {
			return new Role(this, null, null);
		}

		@Override
		public xbean.Role toDataIf() {
			return this;
		}

		public xbean.Role toBeanIf() {
			return new Role(this, null, null);
		}

		// xdb.Bean interface. Data Unsupported
		public boolean xdbManaged() {
			throw new UnsupportedOperationException();
		}
		public xdb.Bean xdbParent() {
			throw new UnsupportedOperationException();
		}
		public String xdbVarname()  {
			throw new UnsupportedOperationException();
		}
		public Long xdbObjId() {
			throw new UnsupportedOperationException();
		}
		public xdb.Bean toConst() {	
			throw new UnsupportedOperationException();
		}
		public boolean isConst() {
			return false;
		}
		public boolean isData() {
			return true;
		}

		@Override
		public String getRolename() { // null
			return rolename;
		}

		@Override
		public com.goldhuman.Common.Octets getRolenameOctets() { // null
			return com.goldhuman.Common.Octets.wrap(getRolename(), xdb.Const.IO_CHARSET);
		}

		@Override
		public long getUserid() { // null
			return userid;
		}

		@Override
		public long getLastlogintime() { // null
			return lastlogintime;
		}

		@Override
		public void setRolename(String _v_) { // null
			if (null == _v_) {
				throw new NullPointerException();
			}
			rolename = _v_;
		}

		@Override
		public void setRolenameOctets(com.goldhuman.Common.Octets _v_) { // null
			this.setRolename(_v_.getString(xdb.Const.IO_CHARSET));
		}

		@Override
		public void setUserid(long _v_) { // null
			userid = _v_;
		}

		@Override
		public void setLastlogintime(long _v_) { // null
			lastlogintime = _v_;
		}

		@Override
		public final boolean equals(Object _o1_) {
			if (!(_o1_ instanceof Role.Data)) {
				return false;
			}
			Role.Data _o_ = (Role.Data) _o1_;
			if (!rolename.equals(_o_.rolename)) {
				return false;
			}
			if (userid != _o_.userid) {
				return false;
			}
			if (lastlogintime != _o_.lastlogintime) {
				return false;
			}
			return true;
		}

		@Override
		public final int hashCode() {
			int _h_ = 0;
			_h_ += rolename.hashCode();
			_h_ += userid;
			_h_ += lastlogintime;
			return _h_;
		}

		@Override
		public String toString() {
			StringBuilder _sb_ = new StringBuilder();
			_sb_.append("(");
			_sb_.append("'").append(rolename).append("'");
			_sb_.append(",");
			_sb_.append(userid);
			_sb_.append(",");
			_sb_.append(lastlogintime);
			_sb_.append(")");
			return _sb_.toString();
		}

	}
}
